<?php

class Web_model extends CI_Model{

	function __construct(){
		parent::__construct();
	}
	
	function getAllInfo(){
		$this->db->select('*');
		$this->db->order_by('id_info', 'DESC');
		$query = $this->db->get('info');
		
		return $query->result_array();
	}
	function getBerita(){
		$this->db->select('*');
		$this->db->order_by('id_berita', 'DESC');
		$this->db->limit(3,3);
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}
	
	function getBeritaByPage($perPage = 0, $offset = 0){
		$this->db->select('*');
		$this->db->order_by('id_berita', 'DESC');
		$this->db->limit($perPage, $offset);
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}
	
	function getAllBerita(){
		$this->db->select('*');
		$this->db->order_by('id_berita', 'DESC');
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}
	
	function getAllAgenda(){
		$this->db->select('*');
		$this->db->order_by('id_agenda', 'DESC');
		$query = $this->db->get('agenda');
		
		return $query->result_array();
	}
	
	function getLimitAgenda(){
		$this->db->select('*');
		$this->db->order_by('id_agenda', 'DESC');
		$this->db->limit(1);
		$query = $this->db->get('agenda');
		
		return $query->result_array();
	}
	
	function getSlider(){
		$this->db->select('*');
		$this->db->order_by('id_berita', 'DESC');
		$this->db->limit(3);
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}
	
	function getDetailBerita($id){
		$this->db->select('*');
		$this->db->where('id_berita',$id);
		$query = $this->db->get('berita');
		
		return $query->result_array();
	}
	
	function getDetailAgenda($id){
		$this->db->select('*');
		$this->db->where('id_agenda',$id);
		$query = $this->db->get('agenda');
		
		return $query->result_array();
	}
	
	function getDetailInfo($id){
		$this->db->select('*');
		$this->db->where('id_info',$id);
		$query = $this->db->get('info');
		
		return $query->result_array();
	}
	
	function getDivisi(){
		$this->db->select('*');
		$this->db->order_by('id_divisi', 'DESC');
		$query = $this->db->get('divisi');
		
		return $query->result_array();
	}
	
	function cariMember($nim){
		//$this->db->select('*');
		//$this->db->where('nim', $nim);
		$query = $this->db->query("select * from member a join divisi b on a.id_divisi=b.id_divisi where a.nim='".$nim."' order by a.nim");
		//$query = $this->db->get('member');
		//return $query;
		return $query->result_array();
	}
	
	function getMateri(){
		$this->db->select('*');
		$this->db->order_by('id_materi', 'DESC');
		$query = $this->db->get('materi');
		
		return $query->result_array();
	}
	
	function getMenu(){
		$this->db->select("*");
		$this->db->where("status", "enable");
		//$this->db->order_by("menu");
		$query = $this->db->get("managemen_menu");
		
		return $query->result_array();
	}
	
	function insert_pildiv($nim,$nama,$hp,$kelas,$jurusan,$sekolah,$jur_sekolah,$divisi,$laptop,$materi,$harapan){
		$data = array(
			'nim'  => $nim,
			'nama' => $nama,
			'hp' => $hp,
			'kelas' => $kelas,
			'jurusan' => $jurusan,
			'sekolah' => $sekolah,
			'asaljurusan' => $jur_sekolah,
			'id_divisi' => $divisi,
			'laptop' => $laptop,
			'materi' => $materi,
			'harapan' => $harapan
		);
		
		$this->db->insert('member', $data);
		if ($this->db->affected_rows() == 1) {
			return TRUE;
		}
		return FALSE;
	}
	
	function search($key,$perPage = 0, $offset = 0){
		$this->db->select('*');
		$this->db->like('judul', $key);
		$this->db->order_by('id_berita', 'DESC');
		$this->db->limit($perPage, $offset);
		$query = $this->db->get ('berita');
		
		return $query->result_array();
	}
	
	function getElearning($key){
		$this->db->select('*');
		$this->db->from('materi');
		$this->db->join('divisi', 'divisi.id_divisi=materi.id_divisi');
		$this->db->where('materi.id_divisi', $key);
		$query=$this->db->get();
		
		return $query->result_array();
	}

}